<?php
//*************************************************************************
//* Bali Open License 1.0
//*
//* The contents of this file are from Bali. You can use it in any way
//* only if you keep this header. 
//*
//* http://www.BaliOnWeb.com
//*
//*************************************************************************

include_once 'libs/config.php';
include_once 'libs/data_wrapper.php';

include_once 'libs/display.php';
include_once 'libs/facebook-platform/client/facebook.php';

$facebook = new Facebook($facebook_config['api_key'], $facebook_config['secret']);
$facebook->require_frame();
$user = $facebook->require_login();
$tab = $_REQUEST['tab'];

print_header();

if('ask' == $tab || '' == $tab){
	$action = $_REQUEST['action'];	
	if('' == $action) {	
		// do nothing
	} else if ('save' == $action) {
		//
		// save stuff to DB
		//
		debug_print($_POST);
		$arr_param['do'] = isset($_REQUEST['submit']) ? 'submit' : 'ignore';
		$arr_param['q_list'] = $_REQUEST['q_list'];
		$arr_param['s_id'] = $_REQUEST['s_id'];
		
		// get a_content
		$arr_q_id = explode("," , $arr_param['q_list']);		
		foreach($arr_q_id as $q_id) {
			$a_tag = 'a_content'.$q_id;
			$a_content = $_POST[$a_tag];
			$arr_param[$a_tag] = $a_content;
		}
				
		$ret = set_answers($arr_param);		
		print 'save page should be here:' . $ret;
	}
	print_tabs(0);
	start_page();
	print_unanswered_q($user);
	close_page();
} else if ('others' == $tab) {
	print_tabs(1);
	start_page();
	close_page();
} else if ('invite' == $tab) {
	print_tabs(2);	
	start_page();
	close_page();
} else {
	$facebook->redirect($APP_ROOT_URL);	
}

?>
